//
//  MCSwitchTabController.m
//  正面金融
//
//  Created by 李李善 on 2018/6/9.
//  Copyright © 2018年 jay. All rights reserved.
//

#import "MCSwitchTabController.h"


@interface MCSwitchTabController ()

@end

@implementation MCSwitchTabController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.viewControllers==nil) {
        NSLog(@"发生错误,MainTabBarViewController的中的控制器为空!!");
        return;
    }else
    {
        MainTabBarViewController *tabBarC = [MainTabBarViewController new];
        tabBarC.panGestureDelegate = self;
        tabBarC.tabBar.hidden = YES;
        tabBarC.viewControllers = self.viewControllers;
        [self addChildViewController:tabBarC];
        [self.view addV:tabBarC.view];
        _tabBarC = tabBarC;
        
        
        MCSwitchTabControl *v = [MCSwitchTabControl new];
        [v addTarget:self action:@selector(onClickSwitchTabControl:) forControlEvents:UIControlEventValueChanged];
        _tabControl = v;
    }
    
    
    
}


-(void)onClickSwitchTabControl:(MCSwitchTabControl *)switchTabControl
{
    self.tabBarC.selectedIndex = switchTabControl.selectedSegmentIndex;
    [switchTabControl segmentLineScrollToIndex:switchTabControl.selectedSegmentIndex animate:YES];
}

-(void)tabBarViewController:(MainTabBarViewController *)tabBarViewController SelectedIndex:(NSInteger)selectedIndex
{
    _tabControl.selectedSegmentIndex =selectedIndex;
    [_tabControl segmentLineScrollToIndex:selectedIndex animate:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
